package com.example.demo.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@Builder
@TableName("user")
@ApiModel("用户实体")
public class User {

    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "用户ID", example = "1")
    private Long userId;

    @ApiModelProperty(value = "用户名", example = "john_doe")
    private String username;

    @JsonIgnore // 序列化时忽略密码字段
    @ApiModelProperty(value = "密码（加密存储）", example = "$2a$10$...", hidden = true)
    private String password;

    @ApiModelProperty(value = "用户角色", example = "USER")
    private UserRole role;

    @TableField(exist = false) // 标记非数据库字段
    @ApiModelProperty(value = "借阅的书籍列表（仅用于业务逻辑）", hidden = true)
    private List<Long> borrowedBooks = new ArrayList<>();


    // 业务逻辑拿到service去实现
    //// 借书方法
    //public void borrowBook(Long book) {
    //    this.borrowedBooks.add(book);
    //    // 这个拿到service业务去做
    //    book.setBorrower(this);
    //}

    //// 还书方法
    //public void returnBook(Book book) {
    //    this.borrowedBooks.remove(book);
    //    book.setBorrower(null);
    //}
}

